//
//  MeatShopLeftTableViewCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/19.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatShopLeftSideCell.h"

@interface MeatShopLeftSideCell()

/**
 左边线条
 */
@property (nonatomic, strong) UIView *leftLineView;

@end


@implementation MeatShopLeftSideCell

#pragma mark - lifecycle methods

- (void)setupUI{
    
    [self addSubview:self.pigPartsLab];
    
    self.leftLineView  = [[UIView alloc] initWithFrame:CGRectMake(0, (self.height - 20)/2.0, 4.f, 20.f)];
    self.leftLineView.backgroundColor = mMainColor;
    [self addSubview:self.leftLineView];
    
    [self addSubview:self.shopCartTipNumber];
}


- (void)setupLayout{
    
    _pigPartsLab.mj_x = 14;
    _pigPartsLab.mj_y = 0;
    _pigPartsLab.width = self.width - 14;
    _pigPartsLab.height = self.height;
    
    _shopCartTipNumber.size = CGSizeMake(16, 16);
    _shopCartTipNumber.mj_y = 3;
    _shopCartTipNumber.mj_x = TJ_MeatShop_LeftSideWidth - _shopCartTipNumber.width - 5;
}



#pragma mark - public methods

- (void)updateToSelectedStateAnimated:(BOOL)animated {
    
    [self animationStateNormal:NO animated:animated];
}


- (void)updateToNormalStateAnimated:(BOOL)animated {
    
    [self animationStateNormal:YES animated:animated];
}


- (void)animationStateNormal:(BOOL)normal animated:(BOOL)animated {
    
    [UIView animateWithDuration:animated ? 0.35 : 0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        
        [self stateNormal:normal];
        
    } completion:nil];
}


- (void)stateNormal:(BOOL)normal {
    
    if (normal) {
        self.leftLineView.alpha = 0.f;
        self.leftLineView.height = 0;
        self.backgroundColor = mBackgroudColor;
        self.pigPartsLab.font = mFont(14);
        self.pigPartsLab.textColor = UIColorFromRGB(0x333333);
        
    } else {
        self.leftLineView.alpha = 1.f;
        self.leftLineView.height = 20.f;
        self.backgroundColor = KWhiteColor;
        self.pigPartsLab.font = mMediumFont(16);
        self.pigPartsLab.textColor = mMainColor;
    }
}


#pragma mark - getter methods

//店铺名称
- (UILabel *)pigPartsLab{
    
    if (!_pigPartsLab) {
        _pigPartsLab = [[UILabel alloc] init];
        _pigPartsLab.textColor = UIColorFromRGB(0x262626);
        _pigPartsLab.textAlignment = NSTextAlignmentLeft;
    }
    return _pigPartsLab;
}

- (UILabel *)shopCartTipNumber{
    if (!_shopCartTipNumber) {
        _shopCartTipNumber = [[UILabel alloc] init];
        _shopCartTipNumber.text = @"1";
        _shopCartTipNumber.textAlignment = NSTextAlignmentCenter;
        _shopCartTipNumber.textColor = KWhiteColor;
        _shopCartTipNumber.font = mMediumFont(11);
        _shopCartTipNumber.backgroundColor = UIColorFromRGB(0xEE5B5B);
        [self addShadowAndCircleCorner:_shopCartTipNumber.layer corner:8];
        _shopCartTipNumber.hidden = YES;
    }
    return _shopCartTipNumber;
}


@end
